package cn.java.Concurrency.executor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 小石潭记
 * @date 2021/12/19 19:55
 * @Description: ${todo}
 */
public class Run2 {
    public static void main(String[] args) {
        try {
            List list = new ArrayList<>();
            list.add(new MyCallableA());
            list.add(new MyCallableB2());

            ExecutorService executor = Executors.newCachedThreadPool();
            // invokeAny 只取得最先完成任务的结果值
            String result = (String) executor.invokeAny(list);
            System.out.println("-----------" + result);
            System.out.println("ZZZZZZZZZZZZ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
